<?php namespace Admin\Controller; 
class IndexController extends CommonController{
    public function index(){
    	$week=array("日","一","二","三","四","五","六");
		$weekday=$week[date('w')];
		View::with('weekday',$weekday);
		View::make();
    }
	public function welcome(){
		View::make();
	}
	//修改密码
	public function changePassword(){
		if(IS_POST){
			//新密码
			$newPwd=Q('post.newPwd');
			//确认新密码
			$confirmPwd=Q('post.confirmPwd');
			//判断密码输入的位数6位
			if(strlen($newPwd)<6){
				View::error('密码不足6位数');
			}
			//判断两次密码输入是否一致
			if($newPwd!=$confirmPwd){
				View::error('两次输入密码不一致');
			}
			//获取数据库中的密码
			$model=new \Admin\Model\Login;
			$password=$model->where(array('aid'=>$_SESSION['info']['aid']))->pluck('adminpwd');
			//判断旧密码是否一致
			$oldPwd=md5(Q('post.oldPwd'));
			if($oldPwd!=$password){
				View::error('旧密码输入有误');
			}
			$model->where(array('aid'=>$_SESSION['info']['aid']))->save(array('adminpwd'=>md5($newPwd)));
			//清除session的值
			session_unset();
			session_destroy();
			$url=U('Login/index');
			$str=<<<str
			<script>
			parent.location.href='{$url}';
			</script>
str;
echo $str;
		
		}
		View::make();
	}
		public function info(){
		$sys = array(
			'os' => PHP_OS,
			'version' => PHP_VERSION,
			'server' => $_SERVER['SERVER_SOFTWARE'],
			'mysql' => mysql_get_server_info(),
			);
			View::with('sys',$sys);
//		$this->sys = $sys;
			View::make();
	}
	
	private function _get_format_time(){
		$arr = array();
		//获取年月日
		$date = date('Y年n月j日');
		$arr['date'] = $date;
		// 获取周几
		$today = getdate();
    	$week = $today['wday'];
    	$weekarr = array('日','一','二','三','四','五','六');
    	$weekday = $weekarr[$week];
    	$arr['weekday'] = $weekday;
    	return $arr;
	}
		
}
